<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class Worklinktotal extends Model
{
    protected $table = 'work_link_total';
    protected $primaryKey = 'id';

    public static function getWorkLinkTotal($kfid)
    {
        return self::where("kfid",$kfid)->first();
    }

    public static function createWorkLinkTotal($kfid)
    {
        return self::insert(["kfid"=>$kfid,"created_at"=>time()]);
    }

    public static function createWorkLinkTotalBatch($workLinkTotal)
    {
        return self::insert($workLinkTotal);
    }

    public static function updateWorkLinkTotal($kfid,$web,$click,$kefu,$qrcode_show,$qrcode_press,$qrcode_card)
    {
        return self::where("kfid",$kfid)->update([
           'web' => DB::raw('web + '.$web),
           'click' => DB::raw('click + '.$click),
           'kefu' => DB::raw('kefu + '.$kefu),
           'qrcode_show' => DB::raw('qrcode_show + '.$qrcode_show),
           'qrcode_press' => DB::raw('qrcode_press + '.$qrcode_press),
           'qrcode_card' => DB::raw('qrcode_card + '.$qrcode_card),
        ]);
    }
}
